module keyboard(clk,key_R,key_C,codeout);
input clk; //时钟信号
input[3:0] key_R; //最左边列是key_R[3]
output reg[3:0] key_C; //最上面行是key_C[3]
output reg[7:0] codeout; //数码管
reg [1:0] cout;


always @(posedge clk)
begin
	if(key_R == 4'hf)
		cout <= cout + 2'd1;
end
//键盘扫描
always @(posedge clk)
begin
  case(cout)
  0:key_C=4'b1110;
  1:key_C=4'b1101;
  2:key_C=4'b1011;
  3:key_C=4'b0111;
  endcase
end

//数码管显示
always @(posedge clk)
begin
  case({key_R,key_C})
      8'b01110111: codeout<=8'h06; //1
		8'b10110111: codeout<=8'h5b; //2
		8'b11010111: codeout<=8'h4f; //3
		8'b11100111: codeout<=8'h77; //A
		8'b01111011: codeout<=8'h66; //4
		8'b10111011: codeout<=8'h6d; //5
		8'b11011011: codeout<=8'h7d; //6
		8'b11101011: codeout<=8'h7c; //B
		8'b01111101: codeout<=8'h07; //7
		8'b10111101: codeout<=8'h7f; //8
		8'b11011101: codeout<=8'h6f; //9
		8'b11101101: codeout<=8'h39; //C
		8'b01111110: codeout<=8'h79; //E
		8'b10111110: codeout<=8'h3f; //0
		8'b11011110: codeout<=8'h71; //F
		8'b11101110: codeout<=8'h5e; //D
  endcase
end

	 
endmodule

